package August;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Day0831 {
    //数组中出现次数超过一半的数字
    public int MoreThanHalfNum_Solution (int[] numbers) {
        int len = numbers.length/2;
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        for (int i = 0; i < numbers.length; i++) {
            if (hashMap.containsKey(numbers[i]))
                hashMap.put(numbers[i],hashMap.get(numbers[i])+1);
            else
                hashMap.put(numbers[i],1);

            if (hashMap.get(numbers[i]) > len)
               return numbers[i];
        }

        return 0;
    }

    //简单错误记录
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){

        }
    }
}
